//
//  MPlusNewsListViewController.m
//  medicineplus
//
//  Created by gufei on 15-5-19.
//  Copyright (c) 2015年 chn_ruby@126.cn. All rights reserved.
//

#import "MPlusNewsListViewController.h"
#import "MPlusNewsTableViewCell.h"
#import "AdView.h"
#import "MPlusDefine.h"

@interface MPlusNewsListViewController ()<UITableViewDataSource,UITableViewDelegate>  {
    AdView * adView;
}
@property (nonatomic, strong) NSMutableArray *aNewsListArray;
@property (nonatomic, retain) UITableView *aTableView;

@end

@implementation MPlusNewsListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _aNewsListArray = [@[@"photo_sample_01",
                         @"photo_sample_02",
                         @"photo_sample_03",
                         @"photo_sample_04",
                         @"photo_sample_05",
                         @"photo_sample_06",
                         @"photo_sample_07",
                         @"photo_sample_08",] mutableCopy];
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-153) style:UITableViewStylePlain];
    // 设置tableView的数据源
    tableView.dataSource = self;
    // 设置tableView的委托
    tableView.delegate = self;
    self.aTableView = tableView;
    self.aTableView.tableHeaderView=[self createScrollView];
    [self.view addSubview:self.aTableView];
    // 去除多余的分割线
    [self setExtraCellLineHidden:_aTableView];
}

- (AdView *)createScrollView {
    NSArray *imagesURL = @[
                           @"http://h.hiphotos.baidu.com/image/w%3D310/sign=8dd427cbe2fe9925cb0c6f5104a95ee4/3ac79f3df8dcd1000d5cc72f708b4710b8122fff.jpg",
                           @"http://h.hiphotos.baidu.com/image/w%3D310/sign=08f04837da33c895a67e9e7ae1127397/8ad4b31c8701a18b80022def9d2f07082938fea0.jpg",
                           @"http://c.hiphotos.baidu.com/image/w%3D310/sign=e27f9caf0ff3d7ca0cf63977c21ebe3c/64380cd7912397dddb1943955a82b2b7d0a2873b.jpg"
                           ];
    
    // 情景三：图片配文字(可选)
    NSArray *titles = @[@"AAOS 单髓内钉效果最好",
                        @"AAOS 单髓内钉效果最好",
                        @"AAOS 单髓内钉效果最好",
                        ];
    
    //如果你的这个广告视图是添加到导航控制器子控制器的View上,请添加此句,否则可忽略此句
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    adView = [AdView adScrollViewWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 180) imageLinkURL:imagesURL placeHoderImageName:@"placeHoder.jpg" pageControlShowStyle:UIPageControlShowStyleLeft];
    
    //    是否需要支持定时循环滚动，默认为YES
    //    adView.isNeedCycleRoll = YES;
    
    [adView setAdTitleArray:titles withShowStyle:AdTitleShowStyleRight];
    //    设置图片滚动时间,默认3s
    //    adView.adMoveTime = 2.0;
    
    //图片被点击后回调的方法
    adView.callBack = ^(NSInteger index, NSString * imageURL)
    {
        
    };
    return adView;;
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return _aNewsListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger row = [indexPath row];
    NSString *cellIdentifier = [NSString stringWithFormat:@"%lu", (unsigned long)row];
    MPlusNewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[MPlusNewsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                     reuseIdentifier:cellIdentifier];
    }
    cell.aTitle.text = @"不合格医师将被清退";
    cell.aImage1.image = [UIImage imageNamed:_aNewsListArray[row]];
    if ((int)indexPath.row%2 == 0) {
        cell.aIntro.hidden = YES;
        cell.aImage2.hidden = NO;
        cell.aImage3.hidden = NO;
        cell.aImage2.image = [UIImage imageNamed:_aNewsListArray[row]];
        cell.aImage3.image = [UIImage imageNamed:_aNewsListArray[row]];
    } else {
        cell.aImage2.hidden = YES;
        cell.aImage3.hidden = YES;
        cell.aIntro.hidden = NO;
        NSString *intro = @"根据部分省市的医师登记信息，发现了很多关于执业资格证";
        [cell.aIntro verticalUpAlignmentWithText:intro maxHeight:40];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //    DetailViewController *detailVC = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
    //    [self.navigationController pushViewController:detailVC animated:YES];
    //消除cell选择痕迹
    [self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 132;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark Table View setExtraCellLineHidden Methods
- (void)setExtraCellLineHidden: (UITableView *)tableView {
    UIView *view =[ [UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    [tableView setTableHeaderView:view];
}

#pragma mark -
#pragma mark Table View Cell deselect Methods
- (void) deselect {
    [_aTableView deselectRowAtIndexPath:[_aTableView indexPathForSelectedRow] animated:YES];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
